#include <iostream>
#include <vector>
#include <cstdio> 

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int >  vec;
typedef pair < int , int > pii;

namespace GenHelper {
    unsigned z1,z2,z3,z4,b;
    unsigned rand_() {
	b=((z1<<6)^z1)>>13;
	z1=((z1&4294967294U)<<18)^b;
	b=((z2<<2)^z2)>>27;
	z2=((z2&4294967288U)<<2)^b;
	b=((z3<<13)^z3)>>21;
	z3=((z3&4294967280U)<<7)^b;
	b=((z4<<3)^z4)>>12;
	z4=((z4&4294967168U)<<13)^b;
	return (z1^z2^z3^z4);
    }
}

void srand(unsigned x) {
    using namespace GenHelper;
    z1=x; z2=(~x)^0x233333333U; z3=x^0x1234598766U; z4=(~x)+51;
}

int read() {
    using namespace GenHelper;
    int a=rand_()&32767;
    int b=rand_()&32767;
    return a*32768+b;
}

const int N = 2e7 + 10;
const int B = 4400;

int n,m;
unsigned s;
int a[N],bel[N];

int val[B + 10];

struct BLOCK {
    int l,r,len;
    int pre[B + 10],suf[B + 10],mx;
    void build() {
	for(int i = l;i <= r;i++) val[i - l + 1] = a[i];
	len = r - l + 1;
	for(int i = 1;i <= len;i++) pre[i] = max(pre[i - 1],val[i]);
	for(int i = len;i >= 1;i--) suf[i] = max(suf[i + 1],val[i]);
    }
    inline int sufmax(int x) { return suf[x - l + 1]; }
    inline int premax(int x) { return pre[x - l + 1]; }
    inline int totmax() { return pre[len]; }
}t[N / B + 10];

int pw[27],lg[N];
int st[27][N / B + 10];

int get(int l,int r) {
    if(l > r) return 0; int k = lg[r - l + 1];
    return max(st[k][l],st[k][r - pw[k] + 1]);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    scanf("%d %d %u",&n,&m,&s); srand(s);
    for(int i = 1;i <= n;i++) a[i] = in;
    for(int i = 1;i <= n;i++) bel[i] = (i - 1) / B + 1,t[bel[i]].r = i;
    for(int i = 1;i <= bel[n];i++) t[i].l = t[i - 1].r + 1;
    for(int i = 1;i <= bel[n];i++) t[i].build(),st[0][i] = t[i].totmax();
    for(int i = 2;i <= bel[n];i++) lg[i] = lg[i >> 1] + 1;
    for(int i = (pw[0] = 1);i <= lg[bel[n]];i++) pw[i] = pw[i - 1] * 2;
    for(int i = 1;i <= lg[bel[n]];i++)
	for(int j = 1;j + pw[i] - 1 <= bel[n];j++)
	    st[i][j] = max(st[i - 1][j],st[i - 1][j + pw[i - 1]]);
    unsigned long long tot = 0;
    for(int i = 1;i <= m;i++) {
	int l = in % n + 1,r = in % n + 1,ans = 0; if(l > r) swap(l,r);
	if(bel[l] == bel[r]) {
	    for(int j = l;j <= r;j++) ans = max(ans,a[j]);
	} else {
	    ans = get(bel[l] + 1,bel[r] - 1);
	    ans = max(ans,t[bel[l]].sufmax(l));
	    ans = max(ans,t[bel[r]].premax(r));
	}
	tot += ans;
    } printf("%llu\n",tot); return 0;
} 
